export function addLongPress (info, clickCb, longPressCb) {
  let timer = null
  let onOff = false
  const { el } = info
  const start = e => {
    // 这里的button的意思是鼠标点击可能不是左键点击可能是右键或者中键点击，所以这里需要判断下
    if (e.type === 'click' || e.button !== 0) return

    if (timer === null) {
      timer = setTimeout(() => {
        onOff = true
        longPressCb && longPressCb(info)
      }, 1000)
    }
  }

  const cancel = e => {
    if (e.type === 'click' && e.button === 0 && !onOff) {
      clickCb && clickCb(info)
    }
    if (timer !== null) {
      clearTimeout(timer)
      timer = null
      onOff = false
    }
  }
  el.addEventListener('mousedown', start)
  el.addEventListener('click', cancel)
  el.addEventListener('mouseout', cancel)
}
